// xc_lshop/business/work/index.js
var actbusiness = require('../model/business_work')
var app = getApp()
Page({
  mixins: [require('../../../xc/mixins/basicMixin')],
  /**
   * 页面的初始数据
   */
  data: {
    basicurl: app.globalData.basicurl,
    statistics: {
      todayVisitor: 0,
      todayNewuser: 0,
      todayOrder: 0,
      todayNewuser: 0,
      todayAmount: 0,
      todayUndelivered: 0,
      todayRefund: 0,
      allMember: 0,
      allAmount: 0,
      payChange: 0,
      payed: 0,
      payednum: 0,
      allOrder: 0,
    },
    busnav:[
      {
        name:"股东贡献",
        icon:"award-o",
        url:"/xc_lshop/business/sharesholder/commission"
      },
      {
        name:"股东分红",
        icon:"balance-list-o",
        url:"/xc_lshop/business/sharesholder/bonus"
      },
      {
        name:"股东拓客",
        icon:"contact",
        url:"/xc_lshop/business/sharesholder/toker"
      }
    ]
  },
  xcloaddata: function (options, config) {
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#000000'
    })
    // var app = getApp()
    // var basicurl=app.globalData["xcsys"]['basicurl']+'/addons/'+app.globalData["xcsys"]['m']+'/';
    // this.setData({basicurl:basicurl})


  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  getStatistics(id) {
    var that = this;
    actbusiness.statistics(id).then(res => {

      if (res["status"] == 1) {
        if (res["obj"]['payChange']) {
          res["obj"]['payChange'] = res["obj"]['payChange'].toFixed(2)
        }
        that.setData({
          statistics: res["obj"]
        })
      }
    })
  },
  afterlogin: function (options, config, userinfo) {
    var that =this;
    if (userinfo.memberinfo ) {
      if (userinfo.memberinfo.authority == 2) {
        that.getStatistics(0)
      }
      else {
        that.nopow(config);      
      }
    } else {
      var app = getApp()
      app.xc_sys_config.authop.oppower("login").then(function (res) {
        if (res["obj"].memberinfo.authority == "2") {
          that.getStatistics(0)
        }
        else {
          that.nopow(config);
        }
        return
      })
    }
  },
  
  nopow(config){
    wx.showModal({
      title: "你没有访问权限",
      content: "你没有访问权限",
      showCancel: true,
      success() {
        console.log("wx.redirectTo9999999999999984444")

        wx.redirectTo({
          url: config.basic.homeurl,
        })
      }

    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

})